package com.skymobi.stc.redis;

import java.lang.reflect.Proxy;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.util.ClassUtils;

public class Jedis2ProxyFactoryBean extends AbstractFactoryBean<Jedis2Commands> {

	private Jedis2Pool jedisPool;

	public Jedis2ProxyFactoryBean() {
		jedisPool = null;
	}

	public Jedis2Pool getJedis2Pool() {
		return jedisPool;
	}

	public void setJedis2Pool(Jedis2Pool jedisPool) {
		this.jedisPool = jedisPool;
	}

	public Class<Jedis2Commands> getObjectType() {
		return Jedis2Commands.class;
	}

	protected Jedis2Commands createInstance() throws Exception {
		PoolInvocationHandler handler = new PoolInvocationHandler(jedisPool);
		return (Jedis2Commands) Proxy.newProxyInstance(
				ClassUtils.getDefaultClassLoader(),
				new Class[] { Jedis2Commands.class }, handler);
	}

}
